package com.gree.flowable.app.services.impl;

import com.gree.flowable.app.mapper.FlowableCommentMapper;
import com.gree.flowable.app.pojo.cmd.AddHisCommentCmd;
import com.gree.flowable.app.pojo.vo.CommentVO;
import com.gree.flowable.app.services.BaseProcessService;
import com.gree.flowable.app.services.IFlowableCommentService;
import com.gree.flowable.app.tools.constants.CommentTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @description: 流程备注service
 */
@Service
public class IFlowableCommentServiceImpl extends BaseProcessService implements IFlowableCommentService {

    @Autowired
    private FlowableCommentMapper flowableCommentMapper;

    @Override
    public void addComment(CommentVO comment) {
        managementService.executeCommand(new AddHisCommentCmd(comment.getTaskId(), comment.getUserId(), comment.getProcessInstanceId(),
                comment.getType(), comment.getMessage()));
    }

    @Override
    public List<CommentVO> getFlowCommentVosByBusinessKey(String businessKey) {
        String instanceId = this.hiFindPorcInsByKey(businessKey);
        List<CommentVO> datas = flowableCommentMapper.getFlowCommentVosByProcessInstanceId(instanceId);
        datas.forEach(commentVo -> {
            commentVo.setTypeName(CommentTypeEnum.getEnumMsgByType(commentVo.getType()));
        });
        return datas;
    }
}
